package ru.evga.inse.server.gwt.admin.client.menu.dict.city;


import java.util.List;

import ru.evga.gwt.lib.common.client.ui.editor.IEntityEditor;
import ru.evga.inse.server.gwt.common.client.domain.dict.CityDto;

import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.DivElement;
import com.google.gwt.editor.client.EditorError;
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HTMLPanel;
import com.google.gwt.user.client.ui.TextBox;

/**
 * Edit view for CityProxy.
 */
public class CityEditPanel extends Composite implements IEntityEditor<CityDto>
{

    interface Binder extends UiBinder<HTMLPanel, CityEditPanel>
    {
    }

    private static final Binder BINDER = GWT.create(Binder.class);

    @UiField
    TextBox nameEditor;
    @UiField
    DivElement errors;

    public CityEditPanel()
    {
        initWidget(BINDER.createAndBindUi(this));
    }

    public void showError(List<EditorError> errors)
    {
        SafeHtmlBuilder b = new SafeHtmlBuilder();
        for (EditorError error : errors)
        {
            b.appendEscaped(error.getPath()).appendEscaped(": ");
            b.appendEscaped(error.getMessage()).appendHtmlConstant("<br>");
        }
        this.errors.setInnerHTML(b.toSafeHtml().asString());
    }

    public void onServiceError(String serviceError)
    {
        SafeHtmlBuilder b = new SafeHtmlBuilder();
        b.appendEscaped(serviceError);
        this.errors.setInnerHTML(b.toSafeHtml().asString());
    }
    
}
